package com.nsy.service.impl;

import com.github.pagehelper.PageHelper;
import com.nsy.dao.UserMapper;
import com.nsy.pojo.SysUser;
import com.nsy.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceimpl implements ISysUserService {
    @Autowired
    private UserMapper userMapper;
    //根据用户名和密码查询用户
    @Override
    public SysUser getUserByUsernameAndPwd(SysUser sysUser) {
        SysUser user = userMapper.getUserByUsernameAndPwd(sysUser);
        return user;
    }
    //获取所有用户
    @Override
    public List<SysUser> getAllUsers(String username,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysUser> users = userMapper.getAllUsers(username);
        return users;
    }

    @Override
    public SysUser getUserById(Integer id) {
        SysUser userById = userMapper.getUserById(id);
        return userById;
    }

    @Override
    public int addUser(SysUser sysUser) {
        int i = userMapper.addUser(sysUser);
        return i;
    }

    @Override
    public int deleteUser(Integer id) {
        int i = userMapper.deleteUser(id);
        return i;
    }

    @Override
    public int editUser(SysUser sysUser) {
        int i = userMapper.editUser(sysUser);
        return i;
    }

    @Override
    public int deleteAllUser(List<String> ids) {
//        int i = userMapper.deleteAllUser(ids);
        int i = userMapper.deleteAllUser(ids);
        return i;
    }
    //根据用户名查询用户
    @Override
    public SysUser getUserByUsername(String username) {
        SysUser user = userMapper.getUserByUsername(username);
        return user;
    }
    //修改密码
    @Override
    public boolean updatePassword(String oldPassword, String newPassword) {
        int result = userMapper.updatePasswordByPassword(oldPassword, newPassword);
        return result > 0;
    }

    @Override
    public SysUser detailUser(Integer id) {
        SysUser user = userMapper.detailUser(id);
        return user;
    }
    //详情

}
